package com.tin.handler;

import com.tin.bean.Msg;
import com.tin.exception.ServiceRuntimeException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.NoHandlerFoundException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 全局异常处理，拦截业务异常
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    //处理业务异常
    @ExceptionHandler(value= ServiceRuntimeException.class)
    @ResponseBody
    public Msg exceptionHandler(ServiceRuntimeException e) {
        String errorCode = e.getErrorCode();
        String errorMsg = e.getErrorMsg();
        return new Msg(errorCode, errorMsg);
    }
}
